package edu.utexas.ipc;


class ReceiveThread extends Thread {

	final int sourceID;
	MessageSource msgInput;
	MessageListener msgOutput;
	
	ReceiveThread(int sourceID, MessageSource in, MessageListener out) {
		this.sourceID = sourceID;
		this.msgInput = in;
		this.msgOutput = out;
	}
	
	public void run() {
		while (true) {
			Message msg = msgInput.read();
			if (msg == null) {
				System.out.println("Exit receive thread for process " + sourceID);
				msgOutput.connectionLost(sourceID);
				return;
			}
			msgOutput.messageReceived(msg);
		}
	}
}
